<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp" %>
<html>
<head>
<base target="_self">
<%@include file="/common/meta.jsp" %>
<%@include file="/common/extjs.jsp" %>
<%@include file="/common/ec.jsp" %>
<title>已付款未销账的借款单</title>
</head>
<body>
<script type="text/javascript">
/**
 * 提交表单
 */
function submitForm(){
	$("#queryForm").submit();
}
</script>
<div class="x-panel">
  <div class="x-toolbar">
    <form id="queryForm" action="selectBorrowIndex.do" method="post">
	    <table width="100%" style="line-height: 25px; height: 30px;">  
	      <tr>
          <td width="60">借款单号：</td>
          <td width="120"><s:textfield name="model.singleNo" cssStyle="width:120px;" />&nbsp;</td>
          <td width="60">开始日期：</td>
          <td width="100"><input id="startDate" name="startDate" size="14"  value="<s:date name='startDate' format='yyyy-MM-dd'/>" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'endDate\')}',skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" class="Wdate"  readonly="readonly"/>&nbsp;&nbsp;</td>
          <td width="60">结束日期：</td>
          <td width="100"><input id="endDate" name="endDate" size="14" value=" <s:date name='endDate' format='yyyy-MM-dd'/>" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'startDate\')}',skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" class="Wdate"  readonly="readonly"/></td>
          <td><s:submit value="查询" cssClass="button" cssStyle="width:45px;"></s:submit></td>
	      </tr>
	    </table>
    </form>
  </div> 
  <div>
	<ec:table items="items" var="item" retrieveRowsCallback="limit" sortRowsCallback="limit" 
		action="selectBorrowIndex.do"
		useAjax="true" doPreload="false"
		maxRowsExported="10000000" 
		pageSizeList="500,ALL" 
		editable="false" 
		sortable="false"	
		rowsDisplayed="500"	
		generateScript="true"	
		resizeColWidth="false"	
		classic="false"	
		width="100%" 	
		height="310px"	
		minHeight="310"
		toolbarContent="navigation|pagejump|pagesize|refresh|extend|status"   >
		<ec:row>
		
        <c:choose>
          <c:when test="${type == 'checkbox'}">
	         <ec:column width="40" property="_s" title="选择" sortable="false" style="text-align:center">
		    	<input type="checkbox" id="${item.id}" name="${item.rePayAmount}" value="${item.amount}" title="${item.singleNo}"  class="checkbox" onclick="checkBorrow(this)"/>
		     </ec:column>
          </c:when>  
          <c:otherwise>
	         <ec:column width="40" property="_s" title="选择" sortable="false" style="text-align:center">
		    	<input type="radio" id="${item.id}" name="${item.rePayAmount}" value="${item.amount}" title="${item.singleNo}"  onclick="checkBorrow(this)" style="border: 0;"/>
		     </ec:column>
          </c:otherwise>
        </c:choose>
		<ec:column width="113" property="_singleNo" title="借款单号" ellipsis="true">
		   <a href="#" onclick="view('${item.id}')" title="${item.title}"><font color="blue">${item.singleNo}</font></a>
		</ec:column>		    
		<ec:column width="113" property="title" title="摘要" ellipsis="true"/>
	    <ec:column width="60" property="borrower.name" title="借款人" style="text-align:center"/>	
		<ec:column width="80" property="createDate" title="借款时间" style="text-align:center" cell="date"/>
		<ec:column width="80" property="amount" title="借款金额" style="text-align:right" format="#####0.00" cell="number"/>	
		<ec:column width="80" property="rePayAmount" title="还款金额" style="text-align:right" format="#####0.00" cell="number"/>
		</ec:row>
	</ec:table>
  </div>
  <div align="center" style="margin: 5px;">
    <input type="button" class="button" value="保存" style="font-weight:bold;" onclick="returnSelectValue()">
    &nbsp;&nbsp;&nbsp;&nbsp;
    <input type="button" class="button" value="关闭" style="font-weight:bold;" onclick="window.close();">
  </div>
</div>
<s:hidden id="selectedBorrowIds" />
<s:hidden id="selectedBorrowNos" />
<s:hidden id="selectedBorrowAmounts" />
<s:hidden id="selectedRePayAmounts" />
<script type="text/javascript">
 var spliteStr = ",";
 function checkBorrow(obj){
  var selectedBorrowIds = $("#selectedBorrowIds").val();
  var selectedBorrowNos =  $("#selectedBorrowNos").val();
  var selectedBorrowAmounts =  $("#selectedBorrowAmounts").val();
  var selectedRePayAmounts =  $("#selectedRePayAmounts").val();
  if (obj.checked){
	  selectedBorrowIds = selectedBorrowIds + obj.id + spliteStr;
	  selectedBorrowNos = selectedBorrowNos + obj.title + spliteStr;
	  selectedBorrowAmounts = selectedBorrowAmounts + obj.value + spliteStr;
	  selectedRePayAmounts = selectedRePayAmounts + obj.name + spliteStr;
  }else{
	  selectedBorrowIds = selectedBorrowIds.replace((obj.id + spliteStr), '');
	  selectedBorrowNos = selectedBorrowNos.replace((obj.title + spliteStr), '');
	  selectedBorrowAmounts = selectedBorrowAmounts.replace((obj.value + spliteStr), '');
	  selectedRePayAmounts = selectedRePayAmounts.replace((obj.name + spliteStr), '');
  }
  $("#selectedBorrowIds").val(selectedBorrowIds);
  $("#selectedBorrowNos").val(selectedBorrowNos);
  $("#selectedBorrowAmounts").val(selectedBorrowAmounts);
  $("#selectedRePayAmounts").val(selectedRePayAmounts);
  
  if ('${type}' == 'radio') {
	 returnSelectValue();
  }
 }

//关闭窗口，返回数据
function returnSelectValue(){
	var borrow = new Object();
	borrow.ids =  $("#selectedBorrowIds").val();
	borrow.nos =  $("#selectedBorrowNos").val();
	borrow.borrowAmounts = $("#selectedBorrowAmounts").val();
	borrow.rePayAmounts = $("#selectedRePayAmounts").val();
	window.returnValue = borrow;
	window.close();
}

function view(id){
	  window.showModalDialog("${ctx}/borrow/view.do?model.id=" + id, null, "dialogWidth=840px;dialogHeight=520px;resizable: Yes;");
	}
</script>
</body>
</html>